<?php

class ArticleModel extends Model {
	
	public function getIndex(){
		$sql = "select a.art_id,a.title,a.cate_id,a.summary,a.author,a.create_time,a.htmlpath,a.clicknum,a.commentnum,c.catename,c.bname 
			from ls_article a, ls_category c where is_index=1 and a.del_flag=0 and a.cate_id=c.cate_id order by art_id desc limit 0,1";
		return $this->pdo->fetchBoth($sql);
	}
	
	public function getRecommend(){
		$sql = "select a.art_id,a.title,a.cate_id,a.author,a.create_time,a.htmlpath,a.clicknum,a.commentnum,c.catename,c.bname 
			from ls_article a, ls_category c where is_commend=1 and a.del_flag=0 and a.cate_id=c.cate_id order by art_id desc limit 0,12";
		return $this->pdo->fetchAllBoth($sql);
	}
	
	public function getArticle($htmlpath){
		$sql = "select a.art_id,a.title,a.cate_id,a.author,a.content,a.create_time,a.htmlpath,a.clicknum,a.commentnum,c.catename,c.bname
			from ls_article a, ls_category c where a.htmlpath=? and a.cate_id=c.cate_id";
		return $this->pdo->fetchBoth($sql,array(array(1,$htmlpath,PDO::PARAM_STR)));
	}
	
	public function getArticleList($map){
		$where = 'where';
		if (!empty($map)){
			$where = $this->buildWhereSql($map);
			$where .= " and ";	
		}
		$sql = "select a.art_id,a.title,a.cate_id,a.author,a.create_time,a.htmlpath,a.clicknum,a.commentnum,c.catename,c.bname 
			from ls_article a, ls_category c ".$where." a.del_flag=0 and a.cate_id=c.cate_id order by art_id desc";
		return $this->pdo->fetchAllBoth($sql);
	}
	
}